//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    hasUserInfo: app.globalData.hasUserInfo,
    canIUse: wx.canIUse('button.open-type.getUserInfo')
  },

  onLoad: function () {
    var that = this
    if (app.globalData.userInfo) {
      that.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    }
  },
  //返回上一页
  tapBack: function () {
    wx.navigateBack({
      delta: 1
    })
  },

  //用户点击登录，获取授权信息
  getUserInfo: function (e) {
    var that = this
    wx.removeStorageSync('SESSION3RD')
    if (e.detail.errMsg != "getUserInfo:fail auth deny") {
      app.getUserInfo(function (cb) {
        if (cb) {
          that.setData({
            userInfo: app.globalData.userInfo,
            hasUserInfo: true
          })
        } else {
          that.setData({
            hasUserInfo: false
          })
          wx.showToast({
            title: '登录失败',
          })
        }
      })
    }
  },

})
